package com.yiyahui.project.erp.service.impl;

import java.util.List;
import com.yiyahui.common.utils.DateUtils;
import com.yiyahui.framework.web.domain.AjaxResult;
import com.yiyahui.project.erp.domain.requestVo.YiyaBatchAddResourceShadow;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yiyahui.project.erp.mapper.YiyaResourceShadowMapper;
import com.yiyahui.project.erp.domain.YiyaResourceShadow;
import com.yiyahui.project.erp.service.IYiyaResourceShadowService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 影像资源Service业务层处理
 * 
 * @author yiyahui
 * @date 2020-05-16
 */
@Service
public class YiyaResourceShadowServiceImpl implements IYiyaResourceShadowService 
{
    @Autowired
    private YiyaResourceShadowMapper yiyaResourceShadowMapper;

    /**
     * 查询影像资源
     * 
     * @param id 影像资源ID
     * @return 影像资源
     */
    @Override
    public YiyaResourceShadow selectYiyaResourceShadowById(Long id)
    {
        return yiyaResourceShadowMapper.selectYiyaResourceShadowById(id);
    }

    /**
     * 查询影像资源列表
     * 
     * @param yiyaResourceShadow 影像资源
     * @return 影像资源
     */
    @Override
    public List<YiyaResourceShadow> selectYiyaResourceShadowList(YiyaResourceShadow yiyaResourceShadow)
    {
        return yiyaResourceShadowMapper.selectYiyaResourceShadowList(yiyaResourceShadow);
    }

    /**
     * 新增影像资源
     * 
     * @param yiyaResourceShadow 影像资源
     * @return 结果
     */
    @Override
    public int insertYiyaResourceShadow(YiyaResourceShadow yiyaResourceShadow)
    {
        yiyaResourceShadow.setCreateTime(DateUtils.getNowDate());
        return yiyaResourceShadowMapper.insertYiyaResourceShadow(yiyaResourceShadow);
    }

    /**
     * 修改影像资源
     * 
     * @param yiyaResourceShadow 影像资源
     * @return 结果
     */
    @Override
    public int updateYiyaResourceShadow(YiyaResourceShadow yiyaResourceShadow)
    {
        yiyaResourceShadow.setUpdateTime(DateUtils.getNowDate());
        return yiyaResourceShadowMapper.updateYiyaResourceShadow(yiyaResourceShadow);
    }

    /**
     * 批量删除影像资源
     * 
     * @param ids 需要删除的影像资源ID
     * @return 结果
     */
    @Override
    public int deleteYiyaResourceShadowByIds(Long[] ids)
    {
        return yiyaResourceShadowMapper.deleteYiyaResourceShadowByIds(ids);
    }

    /**
     * 删除影像资源信息
     * 
     * @param id 影像资源ID
     * @return 结果
     */
    @Override
    public int deleteYiyaResourceShadowById(Long id)
    {
        return yiyaResourceShadowMapper.deleteYiyaResourceShadowById(id);
    }

    @Transactional(rollbackFor=Exception.class)
    public AjaxResult batchInsertYiyaResourceShadow(YiyaBatchAddResourceShadow yiyaBatchAddResourceShadow) throws Exception {
        yiyaBatchAddResourceShadow.getYiyaResourceShadows().forEach(r -> {
            r.setCreateTime(DateUtils.getNowDate());
            yiyaResourceShadowMapper.insertYiyaResourceShadow(r);
        });
        return AjaxResult.success();
    }


}
